package com.lixinlei.springboot_servlet.controller.argumentsresolver.PathVariable;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(path = "/path/variable")
public class PathVariableController {

    /**
     * 模板变量中没有 userId 时，或者为空时，id 为 null
     * @param id
     * @return
     */
    @RequestMapping(path = "/path1")
    public String PathVariable1(@PathVariable(value = "userId", required = false) Integer id) {
        System.out.println("*****************PathVariable1()");
        return "PathVariable1()";
    }

    /**
     * 虽然 required 指定为 false，但是无法将 null 转成 int
     * @param id
     * @return
     */
    @RequestMapping(path = "/path2")
    public String PathVariable2(@PathVariable(value = "userId", required = false) int id) {
        System.out.println("*****************PathVariable2()");
        return "PathVariable2()";
    }

}
